package com.ruoyi.web.controller.vote;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.topic.domain.HouseVoteTopic;
import com.ruoyi.topic.service.IHouseVoteTopicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票题目Controller
 * 
 * @author ruoyi
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/vote/voteTopic")
public class HouseVoteTopicController extends BaseController
{
    @Autowired
    private IHouseVoteTopicService houseVoteTopicService;

    /**
     * 查询投票题目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseVoteTopic houseVoteTopic)
    {
        startPage();
        List<HouseVoteTopic> list = houseVoteTopicService.selectHouseVoteTopicList(houseVoteTopic);
        return getDataTable(list);
    }

    /**
     * 导出投票题目列表
     */
   @Log(title = "投票题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseVoteTopic houseVoteTopic)
    {
        List<HouseVoteTopic> list = houseVoteTopicService.selectHouseVoteTopicList(houseVoteTopic);
        ExcelUtil<HouseVoteTopic> util = new ExcelUtil<HouseVoteTopic>(HouseVoteTopic.class);
        util.exportExcel(response, list, "投票题目数据");
    }

    /**
     * 获取投票题目详细信息
     */
     @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId)
    {
        return AjaxResult.success(houseVoteTopicService.selectHouseVoteTopicByTopicId(topicId));
    }

    /**
     * 新增投票题目
     */
   @Log(title = "投票题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseVoteTopic houseVoteTopic)
    {
        houseVoteTopic.setCreater(getUsername());
        return toAjax(houseVoteTopicService.insertHouseVoteTopic(houseVoteTopic));
    }

    /**
     * 修改投票题目
     */
 @Log(title = "投票题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseVoteTopic houseVoteTopic)
    {
        return toAjax(houseVoteTopicService.updateHouseVoteTopic(houseVoteTopic));
    }

    /**
     * 删除投票题目
     */
    @Log(title = "投票题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topicIds}")
    public AjaxResult remove(@PathVariable Long[] topicIds)
    {
        return toAjax(houseVoteTopicService.deleteHouseVoteTopicByTopicIds(topicIds));
    }

    /**
     * 获取投票题目详细信息
     */
    @GetMapping(value = "/getVoteScore/{voteId}")
    public AjaxResult getVoteScore(@PathVariable("voteId") Long voteId)
    {
        return AjaxResult.success(houseVoteTopicService.selectHouseVoteProjectByVoteId(voteId));
    }
}
